import axios from "axios"
import { showToast } from "vant"

// 1. 创建axios实例对象
const request = axios.create({
  baseURL: 'https://meikou-api.itheima.net/',
  timeout: 50000
})

// 2. 配置请求拦截器
request.interceptors.request.use((config)=>{
  try {
    const user = mk.queryUser()
    if(user.token){
      config.headers.Authorization = `Bearer ${user.token}`
    }
  } catch (error) {
    showToast('美寇商城SDK异常')
  }
  
  return config
}, (error)=>{
  return Promise.reject(error)
})

// 3. 配置响应拦截器

// 4. 导出axios实例对象
export { request }